package com.cskaoyan._19collection._01ds;

import org.junit.Test;

/**
 * @author Macro_Ray
 * @since 2024/3/28 15:57
 */
// 链表的基本操作
public class LinkDemo {
    private String element;

    @Test
    public void test1() {
        // 链表初始化：茶百道、霸王茶姬、蜜雪冰城、茶颜悦色
        /*Node<String> firstNode = new Node<>();
        firstNode.data = "茶百道";

        firstNode.next = new Node<>();
        firstNode.next.data = "霸王茶姬";

        firstNode.next.next = new Node<>();
        firstNode.next.next.data = "蜜雪冰城";

        firstNode.next.next.next = new Node<>();
        firstNode.next.next.next.data = "茶颜悦色";*/


        Node<String> firstNode = new Node<>(element);
        firstNode.data = "茶百道";

        Node<String> secondNode = new Node<>(element);
        secondNode.data = "霸王茶姬";

        firstNode.next = secondNode;

        Node<String> thirdNode = new Node<>(element);
        thirdNode.data = "蜜雪冰城";

        secondNode.next = thirdNode;

        Node<String> fourthNode = new Node<>(element);
        fourthNode.data = "茶颜悦色";

        thirdNode.next = fourthNode;

        // 打印链表
        Node<String> currentNode = firstNode;
        while (currentNode != null) {
            System.out.print(currentNode.data);
            if (currentNode.next != null) {
                System.out.print(" --> ");
            }
            currentNode = currentNode.next;
        }

    }
}

class Node<T> {
    T data;
    Node<T> next;

    public Node(T element) {
        this.data = element;
        this.next = null;
    }
}